/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VolumePanel.java
 *
 * Created on Jul 1, 2009, 3:11:35 PM
 */

package coda.gui;

import org.bff.javampd.MPD;
import org.bff.javampd.MPDPlayer;

/**
 *
 * @author pan
 */
public class VolumePanel extends javax.swing.JPanel {

    private MPD mpd;

    /** Creates new form VolumePanel */
    public VolumePanel(MPD mpd) {
        initComponents();
        //
        this.mpd = mpd;
        //
        MPDPlayer player = mpd.getMPDPlayer();
        try {
            slider.setValue(player.getVolume());
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        slider = new javax.swing.JSlider();
        label = new javax.swing.JLabel();
        label1 = new javax.swing.JLabel();
        muteCheckBox = new javax.swing.JCheckBox();

        setLayout(new java.awt.GridBagLayout());

        slider.setOrientation(javax.swing.JSlider.VERTICAL);
        slider.setFocusable(false);
        slider.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                sliderMouseReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
        add(slider, gridBagConstraints);

        label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/volume.png"))); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
        add(label, gridBagConstraints);

        label1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/mute.png"))); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(8, 4, 0, 4);
        add(label1, gridBagConstraints);

        muteCheckBox.setFocusPainted(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        add(muteCheckBox, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void sliderMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sliderMouseReleased
        MPDPlayer player = mpd.getMPDPlayer();
        try {
            player.setVolume(slider.getValue());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }//GEN-LAST:event_sliderMouseReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel label;
    private javax.swing.JLabel label1;
    private javax.swing.JCheckBox muteCheckBox;
    private javax.swing.JSlider slider;
    // End of variables declaration//GEN-END:variables

}
